When looping through richtext in order to find bold text block elements as in:
string s = "This is some \\b Bold\\b0 \\lang1046\\b Text \\lang1046\\b0 and this is not"
RichText rt
for rt in s do
if(rt.bold)
print rt.text "\n"
This loop can go wrong because there is some richText element in between the bold text. For example: If the string from the object is "This is some \b bold \b0 \lang1046 \b Text \b0 " This script will print: "Bold Text" Instead of "Bold Text" as a whole block. Is there a better(safer) way to loop through bold text blocks? camba - Wed Oct 25 14:46:41 EDT 2017 |
Re: Finding bold text blocks Well, your example has two bold blocks, because a bold text ends with \b0. So isn't the result correct in a way? |
Re: Finding bold text blocks PekkaMakinen - Thu Oct 26 02:58:51 EDT 2017 Well, your example has two bold blocks, because a bold text ends with \b0. So isn't the result correct in a way? Considering the richtext strings, yes there are two blocks. But for a human reader there is only one "This is some Bold Text and this is not". I wanted to do this in a way that guarantees this block, from the perspective of the human reader, is grouped into only one |
Re: Finding bold text blocks camba - Thu Oct 26 07:25:15 EDT 2017 Considering the richtext strings, yes there are two blocks. But for a human reader there is only one "This is some Bold Text and this is not". I wanted to do this in a way that guarantees this block, from the perspective of the human reader, is grouped into only one
string s = "This is some \\b Bold\\b0 \\lang1046\\b Text \\lang1046\\b0 and this is not"
RichText rt
bool bBold = false;
string boldText = "";
for rt in s do {
string txt = rt.text "";
if(!rt.bold && bBold){
if(matches("^[ \t]+$", txt)){
boldText = boldText "" txt "";
}else{
print boldText"\n";
bBold = false;
}
}
if(rt.bold){
if(bBold){
boldText = boldText "" txt "";
}else{
boldText = txt "";
}
bBold = true;
}
}
if(bBold){
print boldText"\n";
}
you'll probably have to resort to something like this then, basically keeping track of the text between the bold passages yourself and only print the text as soon as a non-bold non-whitespace textblock appears. |